package com.jlcindia.dao;

import java.util.List;

import com.jlcindia.hibernate.Customer;
import com.jlcindia.util.HibernateTemplate;

public class HibernateCustomerDAO implements CustomerDAO {

	@Override
	public int addCustomer(Customer cust) {
		Integer it = (Integer)HibernateTemplate.save(cust);
		return it.intValue();
	}

	@Override
	public void updateCustomer(Customer cust) {
		HibernateTemplate.update(cust);
		
	}

	@Override
	public void deleteCustomer(int cid) {
		HibernateTemplate.delete(Customer.class, cid);
		
	}

	@Override
	public Customer getCustomerByCid(int cid) {
		return (Customer)HibernateTemplate.load(Customer.class, cid);
	}

	@Override
	public Customer getCustomerByEmail(String email) {
		String hql = "from Customer c where c.email=?";
		return (Customer)HibernateTemplate.findObject(hql,email);
	}

	@Override
	public Customer getCustomerByCardNo(int accNo) {
		String hql = "from Customer c where c.cardNo=?";
		return (Customer)HibernateTemplate.findObject(hql,accNo);
	}

	@Override
	public List<Customer> getAllCustomers() {
		String hql = "from Customer c";
		return HibernateTemplate.findList(hql);
	}

	@Override
	public List<Customer> getAllCustomers(int start, int total) {
		String hql = "from Customer c";
		return HibernateTemplate.findList(hql,start,total);
		}

	@Override
	public List<Customer> getCustomersByCity(String city) {
		String hql = "from Customer c where c.city = ?";
		return HibernateTemplate.findList(hql,city);
	}

	@Override
	public List<Customer> getCustomersByCity(String city, int start, int total) {
		String hql = "from Customer c where c.city = ?";
		return HibernateTemplate.findList(hql,start,total,city);
	}

	@Override
	public List<Customer> getCustomersByName(String name) {
		String hql = "from Customer c where c.cname = ?";
		return HibernateTemplate.findList(hql,name); 
	}

	@Override
	public List<Customer> getCustomersByName(String name, int start, int total) {
		String hql = "from Customer c where c.name = ?";
		return HibernateTemplate.findList(hql,start,total,name); 
	}

	@Override
	public List<Customer> getCustomersByCardType(String cardType) {
		String hql = "from Customer c where c.cardType = ?";
		return HibernateTemplate.findList(hql,cardType); 
	}

	@Override
	public List<Customer> getCustomersByCardType(String cardType, int start,
			int total) {
		String hql = "from Customer c where c.cardType = ?";
		return HibernateTemplate.findList(hql,start,total,cardType); 
	}

	@Override
	public List<Customer> getCustomersByStatus(String status) {
		String hql = "from Customer c where c.status = ?";
		return HibernateTemplate.findList(hql,status); 
	}

	@Override
	public List<Customer> getCustomersByStatus(String status, int start,
			int total) {
		String hql = "from Customer c where c.status = ?";
		return HibernateTemplate.findList(hql,start,total,status);
	}

	@Override
	public List<Customer> getCustomersByBal(double bal) {
		String hql = "from Customer c where c.cardBal = ?";
		return HibernateTemplate.findList(hql,bal); 
	}

	@Override
	public List<Customer> getCustomersByBal(double bal, int start, int total) {
		String hql = "from Customer c where c.cardBal = ?";
		return HibernateTemplate.findList(hql,start,total,bal); 
	}

	@Override
	public List<Customer> getCustomers(String city, String cardType) {
		String hql = "from Customer c where c.city = ? and c.cardType = ?";
		return HibernateTemplate.findList(hql,city,cardType);
	}

	@Override
	public List<Customer> getCustomers(String city, String cardType, int start,
			int total) {
		String hql = "from Customer c where c.city = ? and c.cardType = ?";
		return HibernateTemplate.findList(hql,start,total,city,cardType);
	}

	@Override
	public List<Customer> getCustomers(String city, String cardType,
			String status) {
		String hql = "from Customer c where c.city = ? and c.cardType = ? and c.status = ?";
		return HibernateTemplate.findList(hql,city,cardType,status); 
	}

	@Override
	public List<Customer> getCustomers(String city, String cardType,
			String status, int start, int total) {
		String hql = "from Customer c where c.city = ? and c.cardType = ? and c.status = ?";
		return HibernateTemplate.findList(hql,start,total,city,cardType,status); 
	}

}
